import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {AuthGuard} from './services/guards/auth.guard';

const routes: Routes = [
  {
    path: '',
    canActivate: [AuthGuard],
    children: [
      // 路由懒加载
      {
        path: 'home', loadChildren: () => import('./pages/home/home.module').then(h => h.HomeModule),
        // CanLoad 守卫：登陆后才加载 HomeModule
        canLoad: [AuthGuard]
      },
      {path: '', loadChildren: () => import('./pages/common/common.module').then(c => c.CommonModule)},
      // {path: '**', pathMatch: 'full', redirectTo: ''}
    ]
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    scrollPositionRestoration: 'enabled'
  })],
  exports: [RouterModule]
})
export class AppRoutingModule {
}
